package com.fz.us.oa.core.dao.com.impl;

import com.fz.us.admin.base.dao.impl.BaseDaoImpl;
import com.fz.us.admin.company.entity.User;
import com.fz.us.oa.core.dao.com.ChatLogDao;
import com.fz.us.oa.core.entity.com.ChatLog;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by ZhuChunXiao on 2017/7/11.
 */
@Repository
public class ChatLogDaoImpl extends BaseDaoImpl<ChatLog, String> implements ChatLogDao {
    @Override
    public List<ChatLog> findChatLogFriend(User own, User friend) {
        String friendId=friend.getId();
        String ownId=own.getId();
        List<ChatLog> chatLogList=getSession().createQuery("from ChatLog c where c.sender=? and c.receiverId=? or c.sender=? and c. receiverId=? order by c.createTime desc")
                .setFirstResult(0)
                .setMaxResults(30)
                .setParameter(0, own)
                .setParameter(1, friendId)
                .setParameter(2, friend)
                .setParameter(3, ownId)
                .list();
                return chatLogList;

    }

    @Override
    public List<ChatLog> findChatLogFriends(User own, List<User> friends) {
//        List<ChatLog> chatLogList=getSession().createQuery("from ChatLog c where c.sender=? and c.receiver in (:list) or c.sender in (:list) and c.receiver=? order by c.createTime desc")
//                .
        return null;
    }

    @Override
    public List<ChatLog> findGroupChatLog(String groupId) {
        List<ChatLog> chatLogList=getSession().createQuery("from ChatLog c where c.receiverId=? order by c.createTime desc")
                .setFirstResult(0)
                .setMaxResults(30)
                .setParameter(0, groupId)
                .list();
        return chatLogList;
    }
}
